package com.zhanghs.contentcenter.controller;

import com.zhanghs.contentcenter.common.CommonResp;
import com.zhanghs.contentcenter.config.TestNacosConfig;
import com.zhanghs.contentcenter.dto.ContentDTO;
import com.zhanghs.contentcenter.entity.TbIndustry;
import com.zhanghs.contentcenter.feignclient.UserFeignClient;
import com.zhanghs.contentcenter.service.TbIndustryService;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.time.LocalDateTime;

/**
 * @Author zhanghongshan
 * @date 2021/9/13 3:57 下午
 */
@RestController
@RequestMapping(value = "/api/content")
@Slf4j
public class ContentController {
    @Autowired
    private UserFeignClient userFeignClient;
    @Autowired
    private TbIndustryService tbIndustryService;
    @Autowired
    private TestNacosConfig testNacosConfig;

    @GlobalTransactional(timeoutMills = 30000 , name = "spring-cloud-demo-tx")
    @GetMapping("/{id}")
    public String userInfo(@PathVariable("id") String id){
        tbIndustryService.insert(TbIndustry.builder().code("1")
                .createName("admin")
                .createUser(1)
                .createTime(LocalDateTime.now())
                .name("xx")
                .build());
        String user = userFeignClient.user(id);
        return user;
    }
    @RequestMapping("/testNacosConfig")
    public TestNacosConfig getTestNacosConfig(){
        return testNacosConfig;
    }

    @GetMapping("/test")
    public CommonResp<ContentDTO> test(@Valid ContentDTO dto){
       return new CommonResp<ContentDTO>().success(dto);
    }


}
